package Greedy;

import Greedy._435_Non_overlappingIntervals.Interval;

import java.util.Arrays;
import java.util.Comparator;

public class _452_MinimumNumberofArrowstoBurstBalloons {
    //attention:when the two ballon are [1,2] and [2,3],you can use an arrow to brust them
    public int findMinArrowShots(int[][] points) {
        if (points.length == 0) {
            return 0;
        }
        int count = 0;
        Arrays.sort(points,new endComparator());
        int end = points[0][1];
        count = 1;
        for (int i = 1; i < points.length; i++) {
            if (points[i][0] > end) {
                count++;
                end = points[i][1];
            }
        }
        return count;

    }

    //the start of the ballon doesn't matter
    class endComparator implements Comparator<int[]> {
        @Override
        public int compare(int[] t1, int[] t2) {
            return t1[1] - t2[1];
        }
    }

}
